﻿using UnityEngine;
using System.Collections;
using UFrameWork;
using System.Collections.Generic;

public class TestView : UView 
{
    public IEnumerator Start()
    {
        WaitForAction action = Action<WaitForAction>("cmd.connect.server");
        yield return action.Wait();

        if (action.IsTimeOut)
        {
            Debug.LogError("连接失败");
            yield break;
        }

        Debug.Log("连接成功");

        StartCoroutine(Hello());
        StartCoroutine(Rank());
    }

    private IEnumerator Hello()
    {
        WaitForAction action = Action<WaitForAction>("cmd.send.hello","你好服务器!");
        yield return action.Wait();

        if (action.IsTimeOut)
        {
            Debug.LogError("获取超时");
            yield break;
        }

        Debug.Log(action.Result<string>());
    }

    private IEnumerator Rank()
    {
        WaitForAction action = Action<WaitForAction>("cmd.send.rank");
        yield return action.Wait();

        if (action.IsTimeOut)
        {
            Debug.LogError("获取超时");
            yield break;
        }

        Debug.Log("self:" + action.Result<int>());

        List<string> list = action.Result<List<string>>(2);

        foreach (string v in list)
        {
            Debug.Log("rank:"+v);
        }
    }
}